/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** ************************************************************************************************
 * @file     Xspi_IpAsm.S                                                                           *
 * @brief    XSPI lld Driver(ASM)                                                                       *
 * @author   Department/Semidrive                                                                     *
 * @date     2024/10/25                                                             *
 *                                                                                                 *
 **************************************************************************************************/
#if defined(__ghs__) || defined(__ghs_asm)
#define XSPI_ASM_PUBLIC  .global
#define XSPI_ASM_FUNCTION(x) x::
#define XSPI_ASM_FUNCTION_END(x)  .endf x
#elif defined(_ARMGCC_C_) || defined(_ARMCLANG_C_) || defined(__GNUC__)
#define XSPI_ASM_PUBLIC  .global
#define XSPI_ASM_FUNCTION(x) .global x; .type x,"function"; x:
#define XSPI_ASM_FUNCTION_END(x)
#elif defined(__IASMARM__) || defined(__ICCARM__)
#define XSPI_ASM_PUBLIC PUBLIC
#define XSPI_ASM_FUNCTION(x) x:
#define XSPI_ASM_FUNCTION_END(x)
#else
#error "XSPI_ASM_FUNCTION undefined"
#endif

#if !defined(CFG_PLATFORM_MCAL)

#if defined(__IASMARM__) || defined(__ICCARM__)
    SECTION .text:CODE(2)
    ARM
#else
    .section ".text"
    .arm
#endif
#else /* defined(CFG_PLATFORM_MCAL) */
#if defined(__IASMARM__) || defined(__ICCARM__)
        SECTION .mcal_text_asm_fls:CODE(2)
        ARM
#elif defined(__ghs__) || defined(__ghs_asm)
        .section ".mcal_text_asm_fls"
#else
        .section ".text"
        .arm
#endif
#endif /*defined(CFG_PLATFORM_MCAL)*/

/* void *Xspi_4BytesAlignedMemcpy(void* dst, void* src, uint32 bytes) */
    XSPI_ASM_PUBLIC Xspi_4BytesAlignedMemcpy
XSPI_ASM_FUNCTION(Xspi_4BytesAlignedMemcpy)
    push {r4-r11}
    mov r3, r0
word8_cp:
    cmp r2, #32
    blt word4_cp
    ldm r1!, {r4-r11}
    stm r0!, {r4-r11}
    sub r2, r2, #32
    b word8_cp
word4_cp:
    cmp r2, #16
    blt word2_cp
    ldm r1!, {r4-r7}
    stm r0!, {r4-r7}
    sub r2, r2, #16
    b word4_cp
word2_cp:
    cmp r2, #8
    blt word_cp
    ldm r1!, {r4-r5}
    stm r0!, {r4-r5}
    sub r2, r2, #8
    b word2_cp
word_cp:
    cmp r2, #0
    beq done
    ldr r4, [r1]
    str r4, [r0]
done:
    mov r0, r3
    pop {r4-r11}
    bx lr
XSPI_ASM_FUNCTION_END(Xspi_4BytesAlignedMemcpy)

#if defined(__IASMARM__) || defined(__ICCARM__)
    END
#endif




/* End of file */
